# -*- coding: utf-8 -*-
import inspect
import traceback
import re
import logging
import logging.handlers

#获取日志句柄
def log_handler(log_level,filepath = None):
	#如果没有文件路径则开启流的方式进行记录
	if filepath is None:
		handler = logging.StreamHandler()
	else:
		handler = logging.FileHandler(filepath,mode = 'w',encoding = 'utf-8') 
	formatter = logging.Formatter('%(module)s.%(funcName)s(line:%(lineno)d):%(message)s')
	handler.setFormatter(formatter)
	return handler

#日志初始化
def log_init(filepath,log_level):
	logger = logging.getLogger()
	logger.setLevel(log_level)
	global easy_mmd_log_handler
	if filepath is not None:
		easy_mmd_log_handler = log_handler(log_level,
			filepath = filepath + '.easy_mmd.mmd.import.log')
	else:
		easy_mmd_log_handler = log_handler(log_level)
	logger.addHandler(easy_mmd_log_handler)

def log_uninit():
	logger = logging.getLogger()
	logger.removeHandler(easy_mmd_log_handler)
